package com.beauty.dressing.module.mine.fragment;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.framework.common.base.IBaseFragment;
import com.beauty.dressing.R;
import com.beauty.dressing.common.bean.LeaseReadyPayResultBean;
import com.beauty.dressing.common.bean.OrderBean;
import com.beauty.dressing.common.bean.User;
import com.beauty.dressing.common.interfaces.OnRecyclerViewItemListener;
import com.beauty.dressing.common.view.LoadingNodataLayout;
import com.beauty.dressing.logic.control.LBController;
import com.beauty.dressing.module.mine.adapter.MyOrderAdapter;
import com.beauty.dressing.module.mine.persenter.OrderPresenter;
import com.beauty.dressing.module.mine.persenter.contract.OrderContract;

import java.util.List;

/**
 * 已完成订单页面
 */
public class CompletedOrderFragment extends IBaseFragment implements OnRecyclerViewItemListener, SwipeRefreshLayout.OnRefreshListener {
    RecyclerView recyclerView;
    MyOrderAdapter myOrderAdapter;
    LoadingNodataLayout nodata_layout;
    SwipeRefreshLayout swiperefresh;

    @Override
    public void setContentView() {
        setContentView(R.layout.common_recycler_no_title);
    }

    @Override
    public void findView() {
        swiperefresh = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
        swiperefresh.setOnRefreshListener(this);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        nodata_layout = (LoadingNodataLayout) findViewById(R.id.nodata_layout);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        if (myOrderAdapter == null) {
            myOrderAdapter = new MyOrderAdapter(context);
        }
        myOrderAdapter.setOnRecyclerViewItemListener(this);
        recyclerView.setAdapter(myOrderAdapter);
    }

    @Override
    public void initData() {
        User user = LBController.getInstance().getCacheManager().getLoginUser();
        orderPresenter.leaseOrder(String.valueOf(user.member_id), String.valueOf(-1), user.token, "1");
//        orderPresenter.leaseOrder(String.valueOf(1), Constants.COMPLETED, "3889f68da98eea80ffaf64ae8cae6ff4347a435c", "1");
    }

    @Override
    public void onClick(View v) {

    }

    OrderPresenter orderPresenter = new OrderPresenter(new OrderContract.ViewControl() {

        @Override
        public void showProgress() {

        }

        @Override
        public void onLeaseOrder(boolean isSuccess, int code, String message, List<OrderBean> list) {
            if (!list.isEmpty()) {
                myOrderAdapter.setData(list);
            } else {
                nodata_layout.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onLeaseReadyPay(boolean isSuccess, int code, String message, LeaseReadyPayResultBean data) {

        }
    });

    @Override
    public void onItemViewOnClick(int type, int position) {
        switch (type) {
            case R.id.right_tv:
                break;
            case R.id.left_tv:
                break;
        }
    }

    @Override
    public void onRefresh() {
        swiperefresh.setRefreshing(false);
    }
}
